﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;

namespace CPPEI.Coolzon.UI
{
    public class FadeSwitchAnimation : SwitchAnimation
    {

        private double _destOpacity = 0;

        protected override void OnPrepare(Storyboard storyboard)
        {
            DoubleAnimation doubleAnimation = null;
            if (SwitchType == UI.SwitchType.In)
            {
                Part.Opacity = 0.1f;
                _destOpacity = 1.0f;
                doubleAnimation = new DoubleAnimation(_destOpacity, new System.Windows.Duration(TimeSpan.FromMilliseconds(300)));
            }
            else
            {
                Part.Opacity = 1.0f;
                _destOpacity = 0.1f;
                doubleAnimation = new DoubleAnimation(_destOpacity, new System.Windows.Duration(TimeSpan.FromMilliseconds(300)));
            }
            Storyboard.SetTarget(doubleAnimation, Part);
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(UIElement.OpacityProperty));
            storyboard.Children.Add(doubleAnimation);
        }

        protected override void OnBegin()
        {
        }

        protected override void OnStop()
        {
        }

        protected override void OnFinish()
        {
            if (this.SwitchType == UI.SwitchType.In)
            {
                Part.Opacity = 1.0f;
            }
            else
            {
                Part.Opacity = 0.1f;
            }
        }
    }
}
